#include "mainwindow.h"

mainwindow::mainwindow(QtDAO* qtdao, QWidget* parent)
{
    qtdao = qtdao;
    //QLabel connect_status_label = QLabel("位移台：未连接 摄像头：未连接");
    this->resize(1600,900);
    this->setWindowTitle("general editor");
    this->init_menu_bar();
    this->init_sub_window();
    this->setMenuBar(bar); // 将菜单栏设置为主窗口的菜单栏

}

mainwindow::~mainwindow(){

}

void mainwindow::init_menu_bar()
{
    bar = new QMenuBar(this);
    QMenu *file = bar->addMenu("File");
    file->addAction("测试打开");
    QMenu *window = bar->addMenu("Window");
    window->addAction("测试打开");
    QMenu *set = bar->addMenu("Set");
    set->addAction("测试打开");
    QMenu *test = bar->addMenu("Test");
    test->addAction("create img");

}

void mainwindow::init_sub_window(){
    this->mdi_area = new MdiArea(qtdao);
    this->create_sub_window(this->mdi_area);
}

void mainwindow::create_sub_window(QDockWidget *obj){
    // 获取现有的 dock 窗口
    QList<QDockWidget*> existing_dock_widgets = findChildren<QDockWidget*>();
    if (!existing_dock_widgets.isEmpty()) {
        // 如果已经有 dock 窗口存在，则在最后一个 dock 窗口的右侧添加
        QDockWidget* last_dock_widget = existing_dock_widgets.last();
        splitDockWidget(last_dock_widget, obj, Qt::Orientation::Horizontal);
    } else {
        // 如果没有 dock 窗口存在，则直接添加到左侧
        addDockWidget(Qt::DockWidgetArea::LeftDockWidgetArea, obj);
    }
}
